home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / ui_xGraphic.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  7.5 KB  |  282 lines

  1. /*****************************************************************************
  2.   FILE           : ui_xGraphic.c
  3.   SHORTNAME      : xGraph.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : Interface to graphic primitives of X
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Tilman Sommer
  10.   DATE           : 18.5.1990
  11.  
  12.   CHANGED BY     :
  13.   IDENTIFICATION : @(#)ui_xGraphic.c    1.9 3/2/94
  14.   SCCS VERSION   : 1.9
  15.   LAST CHANGE    : 3/2/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.              
  19. ******************************************************************************/
  20.  
  21.  
  22. #include <math.h>
  23.  
  24. #include "ui.h"
  25. #include "ui_utilP.h"
  26. #include "ui_setup.h"
  27. #include "ui_action.h"
  28. #include "ui_mainP.h"
  29.  
  30. #include "ui_xGraphic.ph"
  31.  
  32.  
  33. /*****************************************************************************
  34.   FUNCTION : ui_xDrawPoint
  35.  
  36.   PURPOSE  : displays an arrow in the canvas
  37.   RETURNS  : void
  38.   NOTES    : coordinates will be given in canvas pixel coordinates
  39.              the arrow ends at pixPos2
  40.  
  41.   UPDATE   :
  42. *****************************************************************************/
  43.  
  44. void ui_xDrawPoint(Display *displ, Drawable d, GC gc, struct PosType pixPos1)
  45.  
  46. {
  47.     XDrawPoint(displ, d, gc, pixPos1.x, pixPos1.y);
  48. }
  49.  
  50.  
  51. /*****************************************************************************
  52.   FUNCTION : ui_xDrawLine
  53.  
  54.   PURPOSE  : displays an arrow in the canvas
  55.   RETURNS  : void
  56.   NOTES    : coordinates will be given in canvas pixel coordinates
  57.              the arrow ends at pixPos2
  58.  
  59.   UPDATE   :
  60. *****************************************************************************/
  61.  
  62. void ui_xDrawLine(Display *displ, Drawable d, GC gc, struct PosType pixPos1, struct PosType pixPos2)
  63.  
  64. {
  65.     XDrawLine(displ, d, gc, 
  66.           pixPos1.x, pixPos1.y, pixPos2.x, pixPos2.y);
  67. }
  68.  
  69.  
  70. /*****************************************************************************
  71.   FUNCTION : ui_xDrawTriangle
  72.  
  73.   PURPOSE  : displays an arrow in the canvas
  74.   RETURNS  : void
  75.   NOTES    : coordinates will be given in canvas pixel coordinates
  76.              the arrow ends at pixPos2
  77.  
  78.   UPDATE   :
  79. *****************************************************************************/
  80.  
  81. void ui_xDrawTriangle(Display *displ, Drawable d, GC gc, struct PosType pixPos1, struct PosType pixPos2)
  82.  
  83. {
  84.     float    angleCos, angleSin;
  85.     float    vectorX, vectorY;
  86.     float    vectorLength;
  87.     int      i, vtx;
  88.  
  89.  
  90.     struct PosType   vlist_triangle[3];
  91.     int              npts[1];
  92.  
  93.     npts[0] = 3;
  94.     
  95.     /* the coordinates of an arrow pointing in direction of the x axis */
  96.     /* arrow length is 4 pixels, arrow width is 4 pixels */
  97.     /* 0,0 is the endpoint of the arrow */
  98.     vlist_triangle[0].x =   0;
  99.     vlist_triangle[0].y =   0;
  100.     vlist_triangle[1].x = - 4;
  101.     vlist_triangle[1].y =  -2;
  102.     vlist_triangle[2].x = - 4;
  103.     vlist_triangle[2].y =   2;
  104.     
  105.     /* do some calculations needed to perform the graphic rotation */
  106.     vectorX      = pixPos2.x - pixPos1.x;
  107.     vectorY      = pixPos2.y - pixPos1.y;
  108.     vectorLength = sqrt((vectorX * vectorX) + (vectorY * vectorY));
  109.     
  110.     angleCos = 1.0 * vectorX / vectorLength;
  111.     angleSin = sqrt(1.0 - (angleCos * angleCos));
  112.     if (vectorY < 0) angleSin = - angleSin;
  113.     
  114.     for (i=1; i<3; i++) { /* graphic transformation: rotation angle */
  115.     /* Don't transform the center-point (0,0) of the arrow */
  116.     /* store new x coordinate in vtx temporarly */
  117.     vtx =
  118.         angleCos * vlist_triangle[i].x
  119.         - angleSin * vlist_triangle[i].y;
  120.     vlist_triangle[i].y = 
  121.         angleCos * vlist_triangle[i].y 
  122.         + angleSin * vlist_triangle[i].x;
  123.     vlist_triangle[i].x = 
  124.         vtx; /* now update x coordinate too */
  125.     }
  126.     
  127.     
  128.     /* draw arrow */
  129.     /* pw_polygon_2(ui_pw,
  130.        pixPos2.x, pixPos2.y, 
  131.        nbds, npts, vlist_triangle, 
  132.        raster_op, NULL, 0,0); */
  133.  /*   for (i=0; i<3; i++)
  134.     XDrawLine(displ, d, gc, 
  135.           (vlist_triangle[i].x + pixPos2.x),
  136.           (vlist_triangle[i].y + pixPos2.y), 
  137.           (vlist_triangle[(i+1) MOD 3].x + pixPos2.x),
  138.           (vlist_triangle[(i+1) MOD 3].y + pixPos2.y));
  139.  */
  140.     for (i=1; i<3; i++)
  141.     XDrawLine(displ, d, gc, 
  142.           (vlist_triangle[0].x + pixPos2.x),
  143.           (vlist_triangle[0].y + pixPos2.y), 
  144.           (vlist_triangle[i].x + pixPos2.x),
  145.           (vlist_triangle[i].y + pixPos2.y));
  146. }
  147.  
  148.  
  149. /*****************************************************************************
  150.   FUNCTION : ui_xDrawBox
  151.  
  152.   PURPOSE  : draws a box in canvas, 1 pixel thick
  153.   RETURNS  : void
  154.   NOTES    : uses SUNVIEWS pw_vector
  155.  
  156.   UPDATE   :
  157. *****************************************************************************/
  158.  
  159. void ui_xDrawBox(Display *displ, Drawable d, GC gc, struct PosType pixPos1, struct PosType pixPos2)
  160.  
  161. {
  162.     int   xt1, yt1, xt2, yt2; 
  163.  
  164.     ui_utilNormalizeRect(&pixPos1,&pixPos2);
  165.     xt1 = pixPos1.x;
  166.     yt1 = pixPos1.y; 
  167.     xt2 = pixPos2.x;
  168.     yt2 = pixPos2.y;
  169.  
  170.  
  171.     /* (xt1,yt1) is the upper left, (xt2,yt2) is the bottom right coordinate */
  172.  
  173.     XDrawRectangle(displ,d,gc, xt1,yt1, (unsigned int) xt2-xt1, (unsigned int) yt2-yt1);
  174.  
  175. }
  176.  
  177.  
  178. /*****************************************************************************
  179.   FUNCTION : ui_xDrawCrossBox
  180.  
  181.   PURPOSE  : draws a box with a cross inside on a canvas, 1 pixel thick
  182.   RETURNS  : void
  183.   NOTES    : 
  184.  
  185.   UPDATE   :
  186. *****************************************************************************/
  187.  
  188. void ui_xDrawCrossBox(Display *displ, Drawable d, GC gc, struct PosType pixPos1, struct PosType pixPos2)
  189.  
  190. {
  191.     int             xt1, yt1, xt2, yt2; 
  192.     struct PosType  pos1,pos2;
  193.  
  194.     ui_utilNormalizeRect(&pixPos1,&pixPos2);
  195.     pos1.x = pixPos1.x + 1;
  196.     pos1.y = pixPos1.y + 1;
  197.     pos2.x = pixPos2.x - 1;
  198.     pos2.y = pixPos2.y - 1;
  199.  
  200.     /* draw the Box */
  201.     ui_xDrawBox(displ, d, gc, pixPos1, pixPos2);
  202.     ui_xDrawBox(displ, d, gc, pos1   , pos2);
  203.  
  204.     /* draw the Cross */    
  205.     xt1 = pixPos1.x;
  206.     yt1 = pixPos1.y; 
  207.     xt2 = pixPos2.x;
  208.     yt2 = pixPos2.y;
  209.  
  210.     /* (xt1,yt1) is the upper left, (xt2,yt2) is the bottom right coordinate */
  211.  
  212.     if ((xt2-xt1 >= 2) AND (yt2-yt1 >= 2)) {
  213.     /* big enough to draw a cross */
  214.     XDrawLine(displ, d, gc, xt1, yt1, xt2, yt2);
  215.     XDrawLine(displ, d, gc, xt2, yt1, xt1, yt2);
  216.     }
  217. #ifdef DEBUG
  218.     XFlush(ui_display);
  219. #endif
  220. }
  221.  
  222.  
  223. /*****************************************************************************
  224.   FUNCTION : ui_xDeleteRect
  225.  
  226.   PURPOSE  : fills a rectangular whith black or white pixel
  227.   RETURNS  : void
  228.   NOTES    : uses pw_writebackground
  229.  
  230.   UPDATE   :
  231. *****************************************************************************/
  232.  
  233. void ui_xDeleteRect(Display *displ, Drawable d, GC gc, struct PosType pixPos1, struct PosType pixPos2)
  234.  
  235. {
  236.     Dimension         width, height;
  237.  
  238.     ui_utilNormalizeRect(&pixPos1, &pixPos2);
  239.  
  240.     width  = (Dimension) pixPos2.x - pixPos1.x + 1; 
  241.     height = (Dimension) pixPos2.y - pixPos1.y + 1;
  242.  
  243.     XFillRectangle(displ, d, gc, pixPos1.x, pixPos1.y, (unsigned int) width, (unsigned int) height);
  244. }
  245.  
  246.  
  247. /*****************************************************************************
  248.   FUNCTION : ui_xToggleBackingStore
  249.  
  250.   PURPOSE  : toggels the the Backing Store Attibute in a X Window
  251.   RETURNS  : void
  252.   NOTES    : 
  253.  
  254.   UPDATE   : 23.04.1992
  255. ******************************************************************************/
  256.  
  257. void ui_xToggleBackingStore (Boolean toggle, Display *display, Window window)
  258.  
  259. {
  260.     XSetWindowAttributes wa;
  261.  
  262. #ifndef UI_NO_BACKING_STORE
  263.     if (toggle == TRUE) {
  264.         wa.backing_store = Always;
  265.         wa.save_under    = TRUE;
  266.     } else {
  267.         wa.backing_store = NotUseful;
  268.         wa.save_under    = FALSE;
  269.     }
  270.     XChangeWindowAttributes(display, window,
  271.                             CWBackingStore | CWSaveUnder, &wa);
  272. #endif       
  273. }
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280. /* end of file */
  281. /* lines: 270 */
  282.